
#include "stdafx.h"
#include "TcpPortTestPassiveConnectionActor.h"
#include "TcpPortTestActiveConnectionActor.h"
#include "TcpPortTestAcceptActor.h"
#include "TcpPortTestApp.h"

TcpPortTestConfigure::TcpPortTestConfigure()
	:listeningIP_(),listeningPort_(0),serverIP_(),serverPort_(0),doConnect_(false),dataThreadSize_(0)
{

}

TcpPortTestConfigure::~TcpPortTestConfigure()
{
	listeningPort_ = 0;
	serverPort_ = 0;
	doConnect_ = false;
	dataThreadSize_ = 0;
}

retT TcpPortTestConfigure::init( const std::string _configFileName/*=DEFAULT_CONFIG_FILE_NAME*/ )
{
    RNL(ConfigureBase::init("TcpPortTestCfg.xml"));
    try
    {
        listeningIP_ = pt_.get<std::string>("Config.Server.Socket.serverIP");
        listeningPort_=pt_.get<unsigned short>("Config.Server.Socket.serverPort");
		serverIP_ = pt_.get<std::string>("Config.Client.Socket.serverIP");
		serverPort_=pt_.get<unsigned short>("Config.Client.Socket.serverPort");
		doConnect_=pt_.get<bool>("Config.Client.doConnect");
		numToEcho_=pt_.get<int>("Config.Client.numToEcho");
        dataThreadSize_=pt_.get<std::size_t>("Config.Server.dataThreadSize");
    }
    catch(std::exception *)
    {
        return ERROR_APPBASE_INIT_READ_CONFIG_FAIL;
    }
    return CONST_COMMON_SUCCESS;
}

TcpPortTestApp::TcpPortTestApp( ConfigureBase* _pConfigure )
	:AppBase(_pConfigure),pTcpPortTestAcceptActorMgr_(),pTcpPortTestPassiveConnectionActorMgr_(),
	pTcpPortTestActiveConnectionActorMgr_()
{

}

TcpPortTestApp::~TcpPortTestApp()
{
	pTcpPortTestPassiveConnectionActorMgr_.reset();
	pTcpPortTestAcceptActorMgr_.reset();
	pTcpPortTestActiveConnectionActorMgr_.reset();
}

retT TcpPortTestApp::init()
{
    R(AppBase::init());
    pTcpPortTestPassiveConnectionActorMgr_.reset(new TcpPortTestPassiveConnectionActorMgr(((TcpPortTestConfigure*)getApp()->getConfigure())->dataThreadSize_));
    pTcpPortTestAcceptActorMgr_.reset(new TcpPortTestAcceptActorMgr(getWorker(), pTcpPortTestPassiveConnectionActorMgr_));
	pTcpPortTestActiveConnectionActorMgr_.reset(new TcpPortTestActiveConnectionActorMgr(((TcpPortTestConfigure*)getApp()->getConfigure())->dataThreadSize_));
    R(addActorMgr(pTcpPortTestAcceptActorMgr_));
    R(addActorMgr(pTcpPortTestPassiveConnectionActorMgr_));
	R(addActorMgr(pTcpPortTestActiveConnectionActorMgr_));
	RETSUCCESS;
}
